<!-- 搜索表单 -->
<template>
  <ele-card :body-style="{ paddingBottom: '2px' }">
    <el-form label-width="72px" @keyup.enter="search" inline>
      <el-form-item label="所属公司">
        <TenantChoose @loaded="search" v-model="form.tenant_id" />
      </el-form-item>

      <br />
      <el-form-item label="所属站点">
        <SiteRadioAll v-model="form.site_id" @change="search" />
      </el-form-item>

      <br />
      <el-form-item label="状态">
        <el-radio-group v-model="form.status" @change="search">
          <el-radio-button label="">全部</el-radio-button>
          <el-radio-button :label="0">待审核</el-radio-button>
          <el-radio-button :label="1">已处理</el-radio-button>
          <el-radio-button :label="2">已拒绝</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <!-- <el-form-item label="支付方式" v-if="form.status == 1">
        <el-radio-group v-model="form.paid_type" @change="search">
          <el-radio-button label="">全部</el-radio-button>
          <el-radio-button
            v-for="item in typeList"
            :key="item.id"
            :label="item.title"
            :value="item.title"
          >
            {{ item.title }}
          </el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br v-if="form.status == 1" /> -->
      <el-form-item label="提现类型">
        <el-radio-group
          v-model="form.pay_type"
          class="filter-item"
          @change="search"
        >
          <el-radio-button label="">全部</el-radio-button>
          <el-radio-button label="银行卡">银行卡</el-radio-button>
          <el-radio-button label="支付宝">支付宝</el-radio-button>
          <el-radio-button label="微信">微信</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="申请时间">
        <el-date-picker
          v-model="form.startDate"
          class="filter-item"
          type="date"
          placeholder="开始"
          value-format="YYYY-MM-DD"
          style="width: 150px"
        />
        <el-date-picker
          v-model="form.endDate"
          class="filter-item"
          type="date"
          placeholder="结束"
          value-format="YYYY-MM-DD"
          style="width: 150px; margin-left: 8px"
        />
      </el-form-item>
      <br />
      <el-form-item label="处理时间">
        <el-date-picker
          v-model="judgeDateRange"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="generateJudgeDates"
          value-format="YYYY-MM-DD HH:mm:ss"
        />
      </el-form-item>
      <br />
      <el-form-item label="会员名字">
        <el-input clearable v-model.trim="form.realname" />
      </el-form-item>
      <el-form-item label="联系电话">
        <el-input clearable v-model.trim="form.tel" />
      </el-form-item>

      <el-form-item label-width="16px">
        <el-button type="primary" @click="search">查询</el-button>
      </el-form-item>
    </el-form>
  </ele-card>
</template>

<script setup>
  import { EleMessage } from 'ele-admin-plus/es';
  import { getCityList } from '@/api/region';
  import { getTenantList } from '@/api/tenant';
  import { useFormData } from '@/utils/use-form-data';
  import { ref } from 'vue';
  const emit = defineEmits(['search']);
  const props = defineProps({
    /** 弹窗是否打开 */
    modelValue: Boolean,

    where: Object
  });
  /** 表单数据 */
  const [form] = useFormData({
    status: 0,
    tenant_id: 0,
    pay_type: '',
    site_id: 0,
    startDate: '',
    startJudgeDate: '',
    endDate: '',
    endJudgeDate: '',
    realname: '',
    tel: '',
    paid_type: ''
  });
  if (props.where) {
    form.startDate = props.where.startDate ?? '';
    form.endDate = props.where.endDate ?? '';
    form.startJudgeDate = props.where.startJudgeDate ?? '';
    form.endJudgeDate = props.where.endJudgeDate ?? '';
    form.status = props.where.status ?? 0;
  }

  /** 站点数据 */
  // const typeList = ref([]);
  // pageWithdrawPaidType({})
  //   .then((res) => {
  //     typeList.value = res.list;
  //     form.paid_type = res.list[0].title;
  //   })
  //   .catch((e) => {
  //     EleMessage.error(e.message);
  //   });

  /** 日期范围 */
  const judgeDateRange = ref({});
  const generateJudgeDates = () => {
    if (!judgeDateRange.value || judgeDateRange.value.length !== 2) {
      form.startJudgeDate = '';
      form.endJudgeDate = '';
    } else {
      form.startJudgeDate = judgeDateRange.value[0];
      form.endJudgeDate = judgeDateRange.value[1];
    }
    search();
  };

  /** 站点数据 */
  const cityList = ref([]);
  /** 获取站点数据 */
  getCityList({})
    .then((res) => {
      cityList.value = res.list;
      // console.log(res);
      // console.log(form.site_id);
      // form.site_id = res.list[0].site_id;
      // assignFields({
      //   site_id: res[0].site_id
      // });
    })
    .catch((e) => {
      EleMessage.error(e.message);
    });
  /** 租户数据 */
  const tenantList = ref([]);

  /** 获取租户数据 */
  getTenantList({})
    .then((res) => {
      tenantList.value = res.list;
      // console.log(res);
      // console.log(form.site_id);
      // assignFields({
      //   site_id: res[0].site_id
      // });
    })
    .catch((e) => {
      EleMessage.error(e.message);
    });

  /** 搜索 */
  const search = () => {
    console.log(form);
    emit('search', { ...form });
  };
</script>
